﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TurtleLib.ComputerCraft;

namespace TurtleLib.Simulation
{
  public struct TurtleScriptEnvironment
  {
    public TurtleUtility turtle;
    public Term term;
    public PeripheralUtility peripheral;
    public ComputerCraft.OperatingSystem os;
  }

  public delegate void TurtleScript(TurtleScriptEnvironment environment);
}

namespace TurtleLib.ComputerCraft
{
  public partial class Turtle : Computer
  {
    internal class TurtleAccess
    {
      private Turtle _turtle;

      public TurtleAccess(Turtle turtle)
      {
        _turtle = turtle;
      }

      public void SetBootScript(TurtleLib.Simulation.TurtleScript script)
      {
        TurtleLib.Simulation.TurtleScriptEnvironment environment;
        environment.turtle = TurtleUtility;
        environment.term = Term;
        environment.peripheral = PeripheralUtility;
        environment.os = OS;

        var osaccess = new OperatingSystem.OperatingSystemAccess(OS);
        osaccess.SetBoot(() => script(environment));
      }

      public TurtleUtility TurtleUtility { get { return _turtle._turtle; } }
      public Term Term { get { return _turtle._term; } }
      public PeripheralUtility PeripheralUtility { get { return _turtle._peripheral; } }
      public OperatingSystem OS { get { return _turtle._os; } }
    }
  }
}
